//
//  DetailsTableViewController.m
//  HandheldHospital
//
//  Created by lanou3g on 16/3/1.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "DetailsTableViewController.h"
#import "ServiceTableViewCell.h"
#import "SearchController.h"
#import "RegisteredViewController.h"
#import "LineViewController.h"
#import "RouteViewController.h"
#import "TipsViewController.h"
#import "DepartmentViewController.h"
#import "IntroduceViewController.h"
@interface DetailsTableViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)NSMutableArray *hospitalArray;
@property(nonatomic,strong)NSMutableArray *annotationArray;
@property(nonatomic,strong)NSMutableArray *imageArray;

@end

@implementation DetailsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"医院主页";
    self.view.backgroundColor = [UIColor whiteColor];
    //隐藏tabBar
    self.tabBarController.tabBar.hidden = YES;
    [self detailsViews];
    [self detailsTableVIews];
}

// ---------------------------        View layout
- (void)detailsViews
{
    
    UIView *views = [[UIView alloc]init];
    views.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 280);
    views.backgroundColor = [UIColor grayColor];
    views.alpha = 0.2;
    self.tableView.tableHeaderView = views;
    //---------------------------------------------------------------医院路线布局
    UIView *DefuView = [UIView new];
    DefuView.frame = CGRectMake(0, 20, CGRectGetWidth(self.view.bounds), 100);
    DefuView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:DefuView];
    
    //医院名字
    UILabel *hospitalName = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 200, 31)];
    hospitalName.font = [UIFont systemFontOfSize:15];
    hospitalName.text = self.hospital.hospitalName;
    [DefuView addSubview:hospitalName];
    
    //医院等级
    UILabel *hospitaLevel = [[UILabel alloc] initWithFrame:CGRectMake(210, 25, 70, 21)];
    hospitaLevel.backgroundColor = [UIColor grayColor];
    hospitaLevel.font = [UIFont systemFontOfSize:14];
    hospitaLevel.textAlignment = NSTextAlignmentCenter;
    hospitaLevel.alpha = 0.3;
    hospitaLevel.text = self.hospital.hospitalLevel;
    hospitaLevel.layer.borderWidth = 0.1;
    hospitaLevel.layer.borderColor = [UIColor darkGrayColor].CGColor;
    hospitaLevel.layer.cornerRadius = 10.0;
    hospitaLevel.layer.masksToBounds = YES;
    [DefuView addSubview:hospitaLevel];
    
    //医院地址
    UILabel *hospitaAddress = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 250, 31)];
    hospitaAddress.font = [UIFont systemFontOfSize:14];
    hospitaAddress.alpha = 0.5;
    hospitaAddress.text = self.hospital.hospitalAddress;
    [DefuView addSubview:hospitaAddress];
    
    UIButton *route = [UIButton buttonWithType:UIButtonTypeSystem];
    route.frame = CGRectMake(290, 75, 70, 15);
    [route setTitle:@"查看路线" forState:UIControlStateNormal];
    [DefuView addSubview:route];
    
    UIImageView *routeImage = [UIImageView new];
    routeImage.frame = CGRectMake(300, 20, 50, 50);
    routeImage.image = [UIImage imageNamed:@"H8.png"];
    [DefuView addSubview:routeImage];
    
    //添加隐藏View (查看路线)
    UIView *routePoint = [[UIView alloc] initWithFrame:CGRectMake(290, 20, 75, 75)];
    routePoint.backgroundColor = [UIColor whiteColor];
    routePoint.alpha = 0.1;
    [routePoint setUserInteractionEnabled:YES];
    [DefuView addSubview:routePoint];
    
    //添加点击手势 (查看路线)
    UITapGestureRecognizer *routeTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(routeAction:)];
    [routeTap setNumberOfTouchesRequired:1];
    [routePoint addGestureRecognizer:routeTap];
    
//

    //----------------------------------------------------------------医院信息布局
    UIView *DopaView = [UIView new];
    DopaView.frame = CGRectMake(0, 140, CGRectGetWidth(self.view.bounds), 120);
    DopaView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:DopaView];
    
    UIButton *information = [UIButton buttonWithType:UIButtonTypeSystem];
    information.frame = CGRectMake(10, 10, 70, 20);
    information.backgroundColor = [UIColor whiteColor];
    [information setTitle:@"医院信息" forState:UIControlStateNormal];
    [DopaView addSubview:information];
    
    UIView *lineView = [UIView new];
    lineView.frame = CGRectMake(0, 40, CGRectGetWidth(self.view.bounds), 2);
    lineView.backgroundColor = [UIColor grayColor];
    lineView.alpha = 0.1;
    [DopaView addSubview:lineView];
    
    UIButton *introduce = [UIButton buttonWithType:UIButtonTypeSystem];
    introduce.frame = CGRectMake(30, 98, 70, 15);
    introduce.backgroundColor = [UIColor whiteColor];
    [introduce setTitle:@"医院介绍" forState:UIControlStateNormal];
    [DopaView addSubview:introduce];
    
    UIImageView *introduceImage = [UIImageView new];
    introduceImage.frame = CGRectMake(50, 60, 30, 30);
    introduceImage.image = [UIImage imageNamed:@"H4.png"];
    [DopaView addSubview:introduceImage];
    
    UIButton *department = [UIButton buttonWithType:(UIButtonTypeSystem)];
    department.frame = CGRectMake(160, 98, 70, 15);
    [department setTitle:@"科室分布" forState:UIControlStateNormal];
    [DopaView addSubview:department];
    
    UIImageView *departmentImage = [UIImageView new];
    departmentImage.frame = CGRectMake(180, 60, 30, 30);
    departmentImage.image = [UIImage imageNamed:@"H5.png"];
    [DopaView addSubview:departmentImage];
    
    UIButton *tips = [UIButton buttonWithType:(UIButtonTypeSystem)];
    tips.frame = CGRectMake(280, 98, 70, 15);
    [tips setTitle:@"就诊贴士" forState:UIControlStateNormal];
    [DopaView addSubview:tips];
    
    UIImageView *tipsImage = [UIImageView new];
    tipsImage.frame = CGRectMake(300, 60, 30, 30);
    tipsImage.image = [UIImage imageNamed:@"H6.png"];
    [DopaView addSubview:tipsImage];
    
    //添加隐藏View (医院介绍)
    UIView *introducePoint = [[UIView alloc] initWithFrame:CGRectMake(27, 45, 75, 75)];
    introducePoint.backgroundColor = [UIColor whiteColor];
    introducePoint.alpha = 0.1;
    [introducePoint setUserInteractionEnabled:YES];
    [DopaView addSubview:introducePoint];
    
    //添加点击手势 (医院介绍)
    UITapGestureRecognizer *introduceTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(introduceAction:)];
    [introduceTap setNumberOfTouchesRequired:1];
    [introducePoint addGestureRecognizer:introduceTap];
    
    //添加隐藏View (科室分布)
    UIView *departmentPoint = [[UIView alloc] initWithFrame:CGRectMake(157, 45, 75, 75)];
    departmentPoint.backgroundColor = [UIColor whiteColor];
    departmentPoint.alpha = 0.1;
    [departmentPoint setUserInteractionEnabled:YES];
    [DopaView addSubview:departmentPoint];
    
    //添加点击手势 (科室分布)
    UITapGestureRecognizer *departmentTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(departmentAction:)];
    [departmentTap setNumberOfTouchesRequired:1];
    [departmentPoint addGestureRecognizer:departmentTap];
    
    //添加隐藏View (就诊贴士)
    UIView *tipsPoint = [[UIView alloc] initWithFrame:CGRectMake(277, 45, 75, 75)];
    tipsPoint.backgroundColor = [UIColor whiteColor];
    tipsPoint.alpha = 0.1;
    [tipsPoint setUserInteractionEnabled:YES];
    [DopaView addSubview:tipsPoint];
    
    //添加点击手势 (科室分布)
    UITapGestureRecognizer *tipsTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tipsAction:)];
    [tipsTap setNumberOfTouchesRequired:1];
    [tipsPoint addGestureRecognizer:tipsTap];

    
}

#pragma mark    -------    手势 实现

- (void)introduceAction:(UITapGestureRecognizer *)tap
{
    IntroduceViewController *introduce = [IntroduceViewController new];
    introduce.introduce = self.hospital.introduce;
    [self.navigationController pushViewController:introduce animated:YES];
    
}

- (void)departmentAction:(UITapGestureRecognizer *)tap
{
    DepartmentViewController *deparmant = [DepartmentViewController new];
    [self.navigationController pushViewController:deparmant animated:YES];
    
}

- (void)tipsAction:(UITapGestureRecognizer *)tap
{
    TipsViewController *tips = [TipsViewController new];
    [self.navigationController pushViewController:tips animated:YES];
    
}


- (void)routeAction:(UITapGestureRecognizer *)tap
{
    RouteViewController *route = [RouteViewController new];
    [self.navigationController pushViewController:route animated:YES];
    
}





- (void)detailsTableVIews
{
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"ServiceTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"serviceCell"];
    
    self.hospitalArray = [NSMutableArray arrayWithArray:@[@"咨询医生",@"预约挂号",@"排队信息", ]];
    self.annotationArray = [NSMutableArray arrayWithArray:@[@"绑定您的主治医生,享受及时服务",@"提前预约,无需排队",@"查看排队情况,便捷出行"]];
    self.imageArray = [NSMutableArray arrayWithArray:@[@"H9.png",@"H10.png",@"H12.png",]];
    
}
//懒加载
- (NSMutableArray *)hospitalArray
{
    if (_hospitalArray == nil) {
        _hospitalArray = [NSMutableArray array];
    }
    return _hospitalArray;
    
}

//懒加载
- (NSMutableArray *)annotationArray
{
    if (_annotationArray == nil) {
        _annotationArray = [NSMutableArray array];
    }
    return _annotationArray;
    
}


//懒加载
- (NSMutableArray *)imageArray
{
    if (_imageArray == nil) {
        _imageArray = [NSMutableArray array];
    }
    return _imageArray;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.hospitalArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   ServiceTableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"serviceCell" forIndexPath:indexPath];
    
    cell.consultingLabel.text = self.hospitalArray[indexPath.row];
    cell.annotationLabel.text = self.annotationArray[indexPath.row];
    cell.hositeImage.image = [UIImage imageNamed:self.imageArray[indexPath.row]];
    return cell;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *str = self.hospitalArray[indexPath.row];
    NSInteger index = [self.hospitalArray indexOfObject:str];
    [self pushViewControllerByIndex:index];
    
}
- (void)pushViewControllerByIndex:(NSInteger)index
{
    
    switch (index) {
        case 0:
        {
            SearchController *linman = [SearchController new];
            [self.navigationController pushViewController:linman animated:YES];

        }
            break;
            
        case 1:
        {
            RegisteredViewController *registered = [RegisteredViewController new];
            [self.navigationController pushViewController:registered animated:YES];
        }
            break;
        case 2:
        {
            LineViewController *line = [LineViewController new];
            [self.navigationController pushViewController:line animated:YES];
        }break;
    }
    
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
